package com.xinxing.city.recovery.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.xinxing.city.recovery.R;
import com.xinxing.city.recovery.entitys.BucketType;

import java.util.List;

public class MainCataAdapter extends RecyclerView.Adapter<MainCataAdapter.MyViewHolder>{

    private Context mContext;
    List<BucketType> list;

    private ItemListener itemListener;
    public MainCataAdapter(Context mContext, List<BucketType> list) {
        this.mContext = mContext;
        this.list=list;
    }

    /**
     * 设置布局
     * @param viewGroup
     * @param i
     * @return
     */
    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        MyViewHolder holder = new MyViewHolder(LayoutInflater.from(mContext).inflate(R.layout.adapter_category1,viewGroup,false));
        return holder;
    }


    public void setOnItemClickListener(ItemListener listener) {
        this.itemListener = listener;
    }
    /**
     * 为控件绑定数据
     * @param myViewHolder
     * @param position
     */
    @Override
    public void onBindViewHolder(MyViewHolder myViewHolder, @SuppressLint("RecyclerView") int position) {

        myViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                notifyDataSetChanged();
                if(itemListener!=null)
                    itemListener.listener(position);
            }

        });

    }

    /**
     * 返回项个数
     * @return
     */
    @Override
    public int getItemCount() {
        return list.size();
    }

    /**
     * 定义控件并初始化
     */
    class MyViewHolder extends RecyclerView.ViewHolder  {



        public MyViewHolder(View itemView) {
            super(itemView);

        }


    }
    public void setList(List<BucketType> list){
        this.list = list;
        notifyDataSetChanged();
    }

}
